const Router = require('koa-router')
const { verifyToken } = require('@/utils/jwt')
const { verifyAuth } = require('@/middlewares/authMiddlewares/verifyAuth')
const depValidate = require('@/middlewares/validateMiddlewares/depValidate')
const depCheckUpdate = require('@/middlewares/checkUpdateMiddlewares/depUpdate')
const depLog = require('@/middlewares/logMiddlewares/depLog')
const {
  validateSlideCode
} = require('@/middlewares/validateMiddlewares/userValidate')
const depController = require('@/controller/depController')

const router = new Router()
/**
 *  查询部门列表接口
 */
router.get(
  '/list',
  verifyToken(),
  // verifyAuth(['admin.dep.list']),
  depValidate.listDepValidate,
  depController.listDep
)

/**
 * 用户查询自己所在部门接口
 */
router.get(
  '/userDep/list',
  verifyToken(),
  // verifyAuth(['admin.dep.list']),
  depValidate.listDepValidate,
  depController.listUserDep
)

/**
 * 创建部门接口
 */
router.post(
  '/create',
  verifyToken(),
  verifyAuth(['admin.dep.edit']),
  depValidate.createDepValidate,
  depLog.createDepLog,
  depController.createDep
)

/**
 * 更新部门接口
 */
router.put(
  '/update',
  verifyToken(),
  verifyAuth(['admin.dep.edit']),
  depValidate.updateDepValidate,
  depCheckUpdate.singerUpdateCheck,
  depLog.updateDepLog,
  depController.updateDep
)

/**
 * 批量更新部门容量接口
 */
router.put(
  '/setSizeMax',
  verifyToken(),
  verifyAuth(['admin.dep.edit']),
  depValidate.setDepsSizeMaxValidate,
  depCheckUpdate.setSizeMaxUpdateCheck,
  depLog.updateDepLog,
  depController.setDepsSizeMax
)

/**
 * 批量删除部门接口
 */
router.delete(
  '/delete',
  validateSlideCode(),
  verifyToken(),
  verifyAuth(['admin.dep.edit']),
  depValidate.delDepsValidate,
  depCheckUpdate.delDepsSave,
  depLog.delDepLog,
  depController.delDeps
)

/**
 * 部门排序接口
 */
router.put(
  '/sort',
  verifyToken(),
  verifyAuth(['admin.dep.edit']),
  depValidate.sortDepsValidate,
  depController.sortDeps
)
module.exports = router
